package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.RecruitmenPlanBill;
import cn.wolfcode.crm.service.IRecruitmenPlanBillService;
import cn.wolfcode.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("recruitmenPlanBill")
public class RecruitmenPlanBillController {

    @Autowired
    private IRecruitmenPlanBillService recruitmenPlanBillService;


    //根据招聘计划对象Id返回招聘计划明细
    @ResponseBody
    @RequestMapping("getListByPlanId")
    public List<RecruitmenPlanBill> getListByPlanId(Long id){
        if (id==null){
            ArrayList<RecruitmenPlanBill> objects = new ArrayList<>();
            RecruitmenPlanBill bill = new RecruitmenPlanBill();
            bill.setId(1L);
            objects.add(bill);
            return objects;
        }
        return recruitmenPlanBillService.getListByPlanId(id);
    }

    //根据招聘计划对象Id删除招聘计划明细
    @ResponseBody
    @RequestMapping("deleteByPlanId")
    public JsonResult deleteByPlanId(Long id){
        JsonResult result = new JsonResult();
        try {
            if (id!=null){
                recruitmenPlanBillService.deleteByPlanId(id);
            }
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("删除出错!");
        }
        return result;
    }
}
